package org.ehe.business.engineer.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.ehe.business.engineer.domain.EngineerLevelConfigEntity;
import org.ehe.business.engineer.service.EngineerLevelConfigService;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工程师级别配置
 * @author :zhangnn
 * @className :EngineerLevelController
 * @description: TODO
 * @date 2025-07-26 16:47:09
 */

@Slf4j
@RestController
@RequestMapping("/engineerLevel")
@RequiredArgsConstructor
public class EngineerLevelController extends BaseController {

    private final EngineerLevelConfigService engineerLevelConfigService;

    /**
     * 获取列表
     */
    @PostMapping("/list")
    public R<List<EngineerLevelConfigEntity>> list(@RequestBody EngineerLevelConfigEntity configEntity){
        return R.ok(engineerLevelConfigService.queryConfigList(configEntity));
    }

    /**
     * 新增
     * @param configEntity
     * @return
     */
    @SaCheckPermission("engineer:level:add")
    @Log(title = "工程师级别配置增加", linkType = "project", businessType = BusinessType.INSERT, idField = "id", nameField = "levelName")
    @PostMapping("/create")
    public R create(@RequestBody EngineerLevelConfigEntity configEntity){
        String result = engineerLevelConfigService.saveEngineerLevelConfig(configEntity);
        return R.ok(result);
    }

    /**
     * 修改
     * @param configEntity
     * @return
     */
    @SaCheckPermission("engineer:level:edit")
    @Log(title = "工程师级别配置更新", linkType = "project", businessType = BusinessType.UPDATE, idField = "id", nameField = "levelName")
    @PostMapping("/update")
    public R update(@RequestBody EngineerLevelConfigEntity configEntity){
        String result = engineerLevelConfigService.updateEngineerLevelConfig(configEntity);
        return R.ok(result);
    }

    /**
     * 工程师级别删除
     * @param id
     * @return
     */
    @SaCheckPermission("engineer:level:remove")
    @Log(title = "工程师级别配置删除", linkType = "project", businessType = BusinessType.DELETE, idField = "id", nameField = "levelName")
    @DeleteMapping("/{id}")
    public R deleteConfig(@PathVariable Long id) {
        return R.ok("删除工程师级别配置成功", engineerLevelConfigService.deleteConfig(id));
    }
}
